class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if not s:
            return 0
        if len(s) == 1:
            return 1
        max_len = 0
        left = 0
        right = 0
        while right < len(s):
            if s[right] not in s[left:right]:
                right += 1
            else:
                left += 1
            max_len = max(max_len, right - left)
        return max_len